package uiLayer;
import controlLayer.*;
import modelLayer.*;
import java.util.Scanner;
import java.util.ArrayList;

public class StatisticsUI {
   private StatisticsCtr statsCtr;
   private RentUI rentUI;
    
   public StatisticsUI() {
       statsCtr = new StatisticsCtr();
       rentUI = new RentUI();
    }
    
   /**
     * Customers menu methods
     */
    public void statisticsMenu() {
        boolean stop = false;
        
        while(!stop) {
            int choice = writeStatisticsMenu();
            
            switch(choice) {
            case 1 : totalStock();
                break;
            case 2 : monthSales();
                break;
            case 3 : employeeSales();
                break;
            case 4 : monthRents();
                break;
            case 5 : generalStatistics();
                break;
            case 0 : stop = true;
                break;
            default : System.out.println("Invalid command");
                      MainMenuUI.pause();
                break;
            }
        }
    } 
    
    private int writeStatisticsMenu() {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f*** Statistics Menu ***");
        System.out.println("1. Total stock ");
        System.out.println("2. Sales per month ");
        System.out.println("3. Sales per employee ");
        System.out.println("4. Rents turnover by month ");
        System.out.println("5. General statistics ");
        System.out.println("0. Return to main menu ");
        System.out.println("\n Type your choice");
        
        int choice = keyboard.nextInt();
        
        return choice;
    }
    
    /**
     * Customers information input
     */
    private String inputName() {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Enter the name : ");
        String name = keyboard.nextLine();
        return name;
    }
    
    public int inputCprNo() {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Enter the CPR number of the employee : ");
        int cprNo = keyboard.nextInt();
        return cprNo;
    }
    
    /**
     * Customers information show
     */
    private void showName(String name){
        System.out.println("Name : " + name);
    }
    
    /**
     * find Customer
     */
    private void totalStock() {
        double stock = statsCtr.totalStock();
        System.out.println("The total value of the current stock is : " + stock);
        System.out.println();
        MainMenuUI.pause();
    }
    
    private void generalStatistics() {
        String message = statsCtr.generalStatistics();
        System.out.println(message);
        System.out.println();
        MainMenuUI.pause();
    }
    
    private void employeeSales() {
        int cprNo = inputCprNo();
        Employee emp = statsCtr.findEmployee(cprNo);
        if(emp != null) {
            double sales = statsCtr.ordersByEmployee(cprNo);
            System.out.println();
            System.out.println("Total sales for " + emp.getName() + " is : " + sales);
        }
        else {
            System.out.println("No employee was found with the specified CPR number");
        }
        MainMenuUI.pause();
    }
    
    private void monthSales() {
        String month = statsCtr.inputMonth();
        if(!month.isEmpty()) {
            double sales = statsCtr.ordersByMonth(month);
            System.out.println();
            System.out.println("Total sales for month " + month + " is : " + sales);
        }
        else {
            System.out.println("No month specified");
            monthSales();
        }
        MainMenuUI.pause();
    }
    
    private void monthRents() {
        String month = statsCtr.inputMonth();
        if(!month.isEmpty()) {
            double rents = statsCtr.rentsByMonth(month);
            System.out.println();
            System.out.println("Total rents turnover for month " + month + " is : " + rents);
        }
        else {
            System.out.println("No month specified");
            monthSales();
        }
        MainMenuUI.pause();
    }
        
}